﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using OT.Data;
using OT.Models;
using System.Drawing;
using System.IO;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Net.Mail;
using System.Net;
using System.Data;
namespace OT.Controllers
{
    public class HomeController : Controller
    {
        private OTEntitiesme OTDb = new OTEntitiesme();
        HttpCookie myCookie1 = new HttpCookie("LoginSes");
        HttpCookie myCookie2 = new HttpCookie("LoginSesID");
        HttpCookie myCookie3 = new HttpCookie("email");
        public ActionResult ContactUs()
        {
            return View();
        }
        public ActionResult AboutUs()
        {
            return View();
        }
        public ActionResult Index()
        {
            if (Request.Cookies["LoginSes"] != null && Request.Cookies["LoginSesID"] != null)
            {
                int id = Convert.ToInt16( Request.Cookies["LoginSesID"].Value);
                Data.User user = OTDb.Users.Where(r => r.UserID == id ).FirstOrDefault();
                if (user.UserTypeID == 2)
                {
                    Response.Redirect("~/Instructor");
                }
                if (user.UserTypeID == 3)
                {
                    Response.Redirect("~/Student");
                }
            }
            else
            {
                myCookie1.Expires = DateTime.Now.AddDays(-1d);
                Response.Cookies.Add(myCookie1);
                myCookie2.Expires = DateTime.Now.AddDays(-1d);
                Response.Cookies.Add(myCookie2);
            }
            return View();
        }

        [HttpPost]
        public ActionResult Index(Data.User user)
        {
            if (ModelState.IsValid)
            {
                user = OTDb.Users.Where(r => r.EmailAddress == user.EmailAddress && r.Password == Base64Encode(user.Password) && r.UserTypeID == user.UserTypeID).FirstOrDefault();
                if (user == null)
                {
                    ModelState.AddModelError("", "Invalid username or password or usertype!!!");
                }
                else
                {
                    if (user != null && user.UserTypeID == 3)
                    {
                        if (user.Status != true)
                        {
                             ModelState.AddModelError("", "User Blocked , Please Contact to Admin");
                        }
                        else
                        {
                            myCookie1.Expires = DateTime.Now.AddDays(-1d);
                            Response.Cookies.Add(myCookie1);
                            myCookie1.Value = user.FirstName;
                            myCookie1.Expires = DateTime.Now.AddDays(1d);
                            Response.Cookies.Add(myCookie1);

                            ViewBag.user = user.FirstName;
                            myCookie2.Expires = DateTime.Now.AddDays(-1d);
                            Response.Cookies.Add(myCookie2);
                            myCookie2.Value = user.UserID.ToString();
                            myCookie2.Expires = DateTime.Now.AddDays(1d);
                            Response.Cookies.Add(myCookie2);

                            myCookie3.Expires = DateTime.Now.AddDays(-1d);
                            Response.Cookies.Add(myCookie3);
                            myCookie3.Value = user.EmailAddress.ToString();
                            myCookie3.Expires = DateTime.Now.AddDays(1d);
                            Response.Cookies.Add(myCookie3);
                            Response.Redirect("~/Student", false);
                        }
                    }
                    else if (user != null && user.UserTypeID == 2 )
                    {
                        if (user.Status != true)
                        {
                             ModelState.AddModelError("", "User Blocked , Please Contact to Admin");
                        }
                        else
                        {
                            myCookie1.Expires = DateTime.Now.AddDays(-1d);
                            Response.Cookies.Add(myCookie1);
                            myCookie1.Value = user.FirstName;
                            myCookie1.Expires = DateTime.Now.AddDays(1d);
                            Response.Cookies.Add(myCookie1);
                            //Session["LoginSes"] = user.FirstName;
                            ViewBag.user = user.FirstName;
                            myCookie2.Expires = DateTime.Now.AddDays(-1d);
                            Response.Cookies.Add(myCookie2);
                            myCookie2.Value = user.UserID.ToString();
                            myCookie2.Expires = DateTime.Now.AddDays(1d);
                            Response.Cookies.Add(myCookie2);
                            //Session["LoginSesID"] = user.UserID;
                            myCookie3.Expires = DateTime.Now.AddDays(-1d);
                            Response.Cookies.Add(myCookie3);
                            myCookie3.Value = user.EmailAddress.ToString();
                            myCookie3.Expires = DateTime.Now.AddDays(1d);
                            Response.Cookies.Add(myCookie3);
                            Response.Redirect("~/Instructor", false);
                        }
                    }
                }
            }
            return View(user);
        }

        public ActionResult CreateStudent()
        {
            Users User = null;
            try
            {
                User = new Users();
                var usertyp = OTDb.UserTypes.ToList();
                User.UserTypes = usertyp;
                var Country = OTDb.Countries.ToList();
                User.Countrys = Country;
                var Stats = OTDb.States.ToList();
                User.States = Stats;
                var City = OTDb.Cities.ToList();
                User.Citys = City;
            }
            catch (Exception ex)
            {
                Utilities.InsertErrorLog(ex);
            }
            return View(User);
        }

       
        public string ActivationMail(string Emailreceiver)
        {
            string st = "";
            try
            {
                string activationCode = OTDb.Users.Where(u => u.EmailAddress.Trim().Equals(Emailreceiver.Trim())).FirstOrDefault().Guid.Value.ToString();
                string b2 = Request.Url.Authority;
                string b6 = "http://" + b2 + "/Home/SuccessReg?ActivationCode=" + activationCode;
                string body = "Hello " + Request.Cookies["LoginSes"].Value.ToString() + ",";
                body += "<br /><br />Please click the following link to activate your account";
                body += "<br /><a href = '" + b6 + "'>Click here to activate your account.</a>";
                body += "<br /><br />Thanks";
                Utilities.SendEmail(Emailreceiver, "Activation Link for Registration Process", body);
            }
            catch (Exception e)
            {
                Utilities.InsertErrorLog(e);
            }
            return st;
        }
        public static string Base64Encode(string plainText)
        {
            var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
            return System.Convert.ToBase64String(plainTextBytes);
        }

        public static string Base64Decode(string base64EncodedData)
        {
            var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
            return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
        }

        [HttpPost]
        public string CreateStudent(String FirstName, string LastName, String Address, string EmailAddress, string Password, string MobileNo, string LandlineNo, int CountryID, int StateID, int CityID, string Captcha, int UserTypeID = 3)
        {
            if (Session["Captcha"] == null || Session["Captcha"].ToString() != Captcha)
            {
                RedirectToAction("/Home/CreateStudent");
            }
            string result = "";
            User us = null;
            try
            {
                if (ModelState.IsValid)
                {
                    us = new User();
                    us.FirstName = FirstName;
                    us.LastName = LastName;
                    us.Address = Address;
                    us.EmailAddress = Base64Decode(EmailAddress);
                    us.Password = Password;
                    us.MobileNo = MobileNo;
                    us.LandlineNo = LandlineNo;
                    us.CountryID = CountryID;
                    us.StateID = StateID;
                    us.CityID = CityID;
                    us.Status = true;
                    us.RememberMe = false;
                    us.IsVarify = false;
                    us.UserTypeID = UserTypeID;
                    us.LastLoginDate = DateTime.Now;
                    us.CreatedDate = DateTime.Now;
                    us.UpdatedDate = DateTime.Now;
                    us.Guid = Guid.NewGuid();
                    OTDb.Users.Add(us);
                    OTDb.SaveChanges();
                    result = "Sucess";
                    myCookie1.Expires = DateTime.Now.AddDays(-1d);
                    Response.Cookies.Add(myCookie1);
                    myCookie1.Value = us.FirstName;
                    myCookie1.Expires = DateTime.Now.AddDays(1d);
                    Response.Cookies.Add(myCookie1);

                    myCookie2.Expires = DateTime.Now.AddDays(-1d);
                    Response.Cookies.Add(myCookie2);
                    myCookie2.Value = us.UserID.ToString();
                    myCookie2.Expires = DateTime.Now.AddDays(1d);
                    Response.Cookies.Add(myCookie2);

                    myCookie3.Expires = DateTime.Now.AddDays(-1d);
                    Response.Cookies.Add(myCookie3);
                    myCookie3.Value = Base64Decode(EmailAddress); 
                    myCookie3.Expires = DateTime.Now.AddDays(1d);
                    Response.Cookies.Add(myCookie3);

                    ActivationMail(Base64Decode(EmailAddress));
                }
                else
                {
                    var Citys = OTDb.Users.ToList();
                    result = "NotValid";
                }
            }
            catch (Exception ex)
            {
                Utilities.InsertErrorLog(ex);
            }
            return result;
        }

        [HttpGet]
        public ActionResult CreateInstructor()
        {
            Users User = null;
            try
            {
                User = new Users();
                var usertyp = OTDb.UserTypes.ToList();
                User.UserTypes = usertyp;
                var Country = OTDb.Countries.ToList();
                User.Countrys = Country;
                var Stats = OTDb.States.ToList();
                User.States = Stats;
                var City = OTDb.Cities.ToList();
                User.Citys = City;
            }
            catch (Exception ex)
            {
                Utilities.InsertErrorLog(ex);
            }
            return View(User);
        }

        [HttpPost]
        public string CreateInstructor(String FirstName, string LastName, String Address, string EmailAddress, string Password, string MobileNo, string LandlineNo, int CountryID, int StateID, int CityID, string Captcha, int UserTypeID = 2)
        {
            if (Session["Captcha"] == null || Session["Captcha"].ToString() != Captcha)
            {
                RedirectToAction("/Home/CreateInstructor");
            }
            string result = "";
            User us = null;
            try
            {
                if (ModelState.IsValid)
                {
                    us = new User();
                    us.FirstName = FirstName;
                    us.LastName = LastName;
                    us.Address = Address;
                    us.EmailAddress = Base64Decode(EmailAddress);
                    us.Password = Password;
                    us.MobileNo = MobileNo;
                    us.LandlineNo = LandlineNo;
                    us.CountryID = CountryID;
                    us.StateID = StateID;
                    us.CityID = CityID;
                    us.Status = true;
                    us.RememberMe = false;
                    us.IsVarify = false;
                    us.UserTypeID = UserTypeID;
                    us.LastLoginDate = DateTime.Now;
                    us.CreatedDate = DateTime.Now;
                    us.UpdatedDate = DateTime.Now;
                    us.Guid = Guid.NewGuid();
                    OTDb.Users.Add(us);
                    OTDb.SaveChanges();
                    result = "Sucess";
                    myCookie1.Expires = DateTime.Now.AddDays(-1d);
                    Response.Cookies.Add(myCookie1);
                    myCookie1.Value = us.FirstName;
                    myCookie1.Expires = DateTime.Now.AddDays(1d);
                    Response.Cookies.Add(myCookie1);

                    myCookie2.Expires = DateTime.Now.AddDays(-1d);
                    Response.Cookies.Add(myCookie2);
                    myCookie2.Value = us.UserID.ToString();
                    myCookie2.Expires = DateTime.Now.AddDays(1d);
                    Response.Cookies.Add(myCookie2);

                    myCookie3.Expires = DateTime.Now.AddDays(-1d);
                    Response.Cookies.Add(myCookie3);
                    myCookie3.Value = Base64Decode(EmailAddress);
                    myCookie3.Expires = DateTime.Now.AddDays(1d);
                    Response.Cookies.Add(myCookie3);

                    ActivationMail(Base64Decode(EmailAddress));
                }
                else
                {
                    var Citys = OTDb.Users.ToList();
                    result = "NotValid";
                }
            }
            catch (Exception ex)
            {
                Utilities.InsertErrorLog(ex);
            }
            return result;
        }

        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult CapValid(string cap)
        {
            string res;
            if (Session["Captcha"] == null || Session["Captcha"].ToString() != cap)
            {
                res = "invalid";
            }
            else
            {
                res = "valid";
            }

            return Json(res, JsonRequestBehavior.AllowGet);
        }

        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult Avail(string EmailID1)
        {
            var cnt = OTDb.Users.Where(p => p.EmailAddress.Equals(EmailID1)).Count();
            return Json(cnt, JsonRequestBehavior.AllowGet);
        }

        private IList<State> GetState(int CountryID)
        {
            return OTDb.States.Where(m => m.CountryID == CountryID).ToList();
        }

        private IList<City> GetCity(int StateID)
        {
            return OTDb.Cities.Where(c => c.StateID == StateID).ToList();
        }

        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult LoadState(string CountryID)
        {
            if (CountryID != "") 
            {
                var stateList = this.GetState(Convert.ToInt32(CountryID));
                var stateData = stateList.Select(m => new SelectListItem()
                {
                    Text = m.StateName,
                    Value = m.StateID.ToString(),
                });
                return Json(stateData, JsonRequestBehavior.AllowGet);
            }
            return Json(CountryID);
        }

        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult LoadCity(string StateID)
        {
            var CityList = this.GetCity(Convert.ToInt32(StateID));
            var CityData = CityList.Select(c => new SelectListItem()
            {
                Text = c.CityName,
                Value = c.CityID.ToString(),
            });
            return Json(CityData, JsonRequestBehavior.AllowGet);
        }

        public ActionResult CaptchaImage(string prefix = null, bool noisy = true)
        {
            var rand = new Random((int)DateTime.Now.Ticks);
            int a = rand.Next(10, 99);
            int b = rand.Next(0, 9);
            int num = rand.Next(0, 26);
            char c = (char)('a' + num);
            char d = (char)('a' + b);
            var captcha = string.Format("{0}{1}{2}{3}", a, d, b, c);
            Session["Captcha"] = captcha;
            //image stream 
            FileContentResult img = null;
            using (var mem = new MemoryStream())
            using (var bmp = new Bitmap(130, 30))
            using (var gfx = Graphics.FromImage((Image)bmp))
            {
                gfx.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                gfx.SmoothingMode = SmoothingMode.AntiAlias;
                gfx.FillRectangle(Brushes.White, new Rectangle(0, 0, bmp.Width, bmp.Height));
                HatchBrush hatchBrush1 = new HatchBrush(HatchStyle.SmallConfetti,
                Color.Gray, Color.White);
                gfx.FillRectangle(hatchBrush1, new Rectangle(0, 0, bmp.Width, bmp.Height));
                //add noise 
                if (noisy)
                {
                    int i, r, x, y, u, v;
                    var pen = new Pen(Color.Yellow);
                    for (i = 1; i < 7; i++)
                    {
                        pen.Color = Color.FromArgb(
                        (rand.Next(0, 255)),
                        (rand.Next(0, 255)),
                        (rand.Next(0, 255)));
                        r = rand.Next(0, (130 / 3));
                        x = rand.Next(0, 130);
                        y = rand.Next(0, 30);
                        u = x - r;
                        v = y - r;
                        gfx.DrawEllipse(pen, u, v, r, r);
                    }
                }
                gfx.DrawString(captcha, new Font("Elephant", 18), Brushes.Gray, 2, 2);
                bmp.Save(mem, System.Drawing.Imaging.ImageFormat.Jpeg);
                img = this.File(mem.GetBuffer(), "image/Jpeg");
            } return img;
        }
     
        [HttpGet]
        public ActionResult SuccessReg()
        {
            string activationCode = !string.IsNullOrEmpty(Request.QueryString["ActivationCode"]) ? Request.QueryString["ActivationCode"] : Guid.Empty.ToString();

            if (activationCode != "00000000-0000-0000-0000-000000000000")
            {
                // var que = OTDb.Users.Where(u => u.Guid.Equals(activationCode)).FirstOrDefault().Status = true;
                Guid gd = Guid.Parse(activationCode);
                var User1 = OTDb.Users.Where(u => u.Guid.Value.Equals(gd)).FirstOrDefault();
                if (User1 != null)
                {
                    User1.Status = true;
                    User1.Guid = Guid.Empty;
                    User1.IsVarify = true;
                    OTDb.SaveChanges();
                    if (User1.UserTypeID == 3)
                    {
                        ModelState.AddModelError("", "Successfully Activation .!!");
                        myCookie1.Expires = DateTime.Now.AddDays(-1d);
                        Response.Cookies.Add(myCookie1);
                        myCookie1.Value = User1.FirstName;
                        myCookie1.Expires = DateTime.Now.AddDays(1d);
                        Response.Cookies.Add(myCookie1);
                     
                        myCookie2.Expires = DateTime.Now.AddDays(-1d);
                        Response.Cookies.Add(myCookie2);
                        myCookie2.Value = User1.UserID.ToString();
                        myCookie2.Expires = DateTime.Now.AddDays(1d);
                        Response.Cookies.Add(myCookie2);
                       
                    }
                    else
                    {
                        ModelState.AddModelError("", "Successfully Activation .!!");
                        myCookie1.Expires = DateTime.Now.AddDays(-1d);
                        Response.Cookies.Add(myCookie1);
                        myCookie1.Value = User1.FirstName;
                        myCookie1.Expires = DateTime.Now.AddDays(1d);
                        Response.Cookies.Add(myCookie1);

                        myCookie2.Expires = DateTime.Now.AddDays(-1d);
                        Response.Cookies.Add(myCookie2);
                        myCookie2.Value = User1.UserID.ToString();
                        myCookie2.Expires = DateTime.Now.AddDays(1d);
                        Response.Cookies.Add(myCookie2);
                        Response.Redirect("/Instructor");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Invalid Activation code.");
                }
            }
            else
            {
                ModelState.AddModelError("", "Successfuly Registered !!please , kindlly Checkout your Inbox for Varification Mail");
            }
            return View();
        }
        public int GoogleCall(string EmailAddress, string FirstName, string LastName)
        {
            int res = 0;
            if (EmailAddress != "" && EmailAddress != null)
            {
                try
                {
                    if (ModelState.IsValid)
                    {
                        User us = new User();
                        us.EmailAddress = EmailAddress;
                        us.FirstName = FirstName;
                        us.LastName = LastName;
                        us.UserTypeID = 3;
                        us.LastLoginDate = DateTime.Now;
                        us.CreatedDate = DateTime.Now;
                        us.UpdatedDate = DateTime.Now;
                        us.Guid = Guid.NewGuid();
                        us.IsVarify = true;
                        us.Status = true;
                        us.LoginWith = "Google+";
                        OTDb.Users.Add(us);
                        res = 1;
                        OTDb.SaveChanges();
                        res = 0;
                        myCookie1.Expires = DateTime.Now.AddDays(-1d);
                        Response.Cookies.Add(myCookie1);
                        myCookie1.Value = FirstName;
                        myCookie1.Expires = DateTime.Now.AddDays(1d);
                        Response.Cookies.Add(myCookie1);

                        myCookie2.Expires = DateTime.Now.AddDays(-1d);
                        Response.Cookies.Add(myCookie2);
                        myCookie2.Value = us.UserID.ToString();
                        myCookie2.Expires = DateTime.Now.AddDays(1d);
                        Response.Cookies.Add(myCookie2);
                    }
                    else
                    {
                        var Citys = OTDb.Users.ToList();
                        res = 1;
                    }
                }
                catch (Exception ex)
                {
                    Utilities.InsertErrorLog(ex);
                }
            }
            return res;
        }
        public int FacebookCallback(Data.User user)
        {
            string[] sep = { "," };
            string[] IDs = user.Address.Split(sep, StringSplitOptions.RemoveEmptyEntries);
            List<string> ids = new List<string>();
            foreach (var name in IDs)
                ids.Add(name);
            string cname = ids[0];
            City city = OTDb.Cities.Where(c => c.CityName.Trim().Equals(cname.Trim())).FirstOrDefault();
            if (city != null)
            {
                user.CityID = city.CityID;
                user.StateID = city.StateID.Value;
                user.CountryID = city.State.CountryID.Value;
            }
            user.UserTypeID = 3;
            user.IsVarify = true;
            user.LoginWith = "Facebook";
            user.Status = true;
            user.RememberMe = true;
            user.Guid = Guid.NewGuid();
            user.CreatedDate = DateTime.Today;
            user.UpdatedDate = DateTime.Today;
            OTDb.Users.Add(user);
            OTDb.SaveChanges();
            myCookie1.Expires = DateTime.Now.AddDays(-1d);
            Response.Cookies.Add(myCookie1);
            myCookie1.Value = user.FirstName;
            myCookie1.Expires = DateTime.Now.AddDays(1d);
            Response.Cookies.Add(myCookie1);

            myCookie2.Expires = DateTime.Now.AddDays(-1d);
            Response.Cookies.Add(myCookie2);
            myCookie2.Value = user.UserID.ToString();
            myCookie2.Expires = DateTime.Now.AddDays(1d);
            Response.Cookies.Add(myCookie2);
            return 0;
        }

        public JsonResult GetUserDetail(string EmailID)
        {
            Users userdetail = new Users();
            try
            {
                userdetail = (from u in OTDb.Users
                              where u.EmailAddress.Trim().Equals(EmailID)
                              select new Users
                               {
                                   Password = u.Password,
                                   EmailAddress = u.EmailAddress,
                                   UserTypeID = (int)u.UserTypeID,
                                   UserID = u.UserID,
                                   FirstName=u.FirstName,
                                   LoginWith=u.LoginWith
                               }).FirstOrDefault();
            }
            catch (Exception ex)
            {
                Utilities.InsertErrorLog(ex);
            }
            return Json(userdetail, JsonRequestBehavior.AllowGet);
        }

        public int StudentLogin(string FirstName,int UserID)
        {
            myCookie1.Expires = DateTime.Now.AddDays(-1d);
            Response.Cookies.Add(myCookie1);
            myCookie1.Value = FirstName;
            myCookie1.Expires = DateTime.Now.AddDays(1d);
            Response.Cookies.Add(myCookie1);

            myCookie2.Expires = DateTime.Now.AddDays(-1d);
            Response.Cookies.Add(myCookie2);
            myCookie2.Value = UserID.ToString();
            myCookie2.Expires = DateTime.Now.AddDays(1d);
            Response.Cookies.Add(myCookie2);
            return 0;
        }

        [HttpGet]
        public ActionResult RecoverPassWord()
        {
            string activationCode = !string.IsNullOrEmpty(Request.QueryString["ActivationCode"]) ? Request.QueryString["ActivationCode"] : Guid.Empty.ToString();
            return View();
        }

        [HttpPost]
        public string RecoverPassWord(Users user)
        {
            string result = "valid";
            var User1 = OTDb.Users.Where(u => u.Guid.Value.Equals(user.guid)).FirstOrDefault();
            if (User1 != null)
            {
                if (User1.UserTypeID == 3)
                {
                    User1.Password = Base64Decode(user.Password);
                    User1.Guid = Guid.Empty;
                    OTDb.SaveChanges();
                    Utilities.SendEmail(User1.EmailAddress, "PassWord Changed!!", "Your PassWord is Successfully Changed");
                    return result="valid";
                }
                else if (User1.UserTypeID == 2)
                {
                    User1.Password = Base64Decode(user.Password);
                    User1.Guid = Guid.Empty;
                    OTDb.SaveChanges();
                    Utilities.SendEmail(User1.EmailAddress, "PassWord Changed!!", "Your PassWord is Successfully Changed");
                    return result="valid";
                }
            }
            else
            {
                return result = "Notvalid";
            }
            return result;
        }

        [HttpGet]
        public ActionResult ForgotPword()
        {
            return PartialView();
        }

        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult Retrieve(string emailID)
        {
            string res = "";
            if (emailID != "")
            {
                try
                {
                    var User1 = OTDb.Users.Where(u => u.EmailAddress.Trim().Equals(emailID.Trim())).FirstOrDefault();
                    if (User1 != null)
                    {
                        User1.Guid = Guid.NewGuid();
                        OTDb.SaveChanges();
                        if (User1.UserTypeID == 3)
                        {
                            string b2 = Request.Url.Authority;
                            string b6 = "http://" + b2 + "/home/RecoverPassWord?ActivationCode=" + User1.Guid.ToString();
                            string body = "Hello " + ",";
                            body += "<br /><br />Please click the following link to Reset Your PassWord";
                            body += "<br /><a href = '" + b6 + "'>Click here to Reset your account PassWord.</a>";
                            body += "<br /><br />Thanks";
                            Utilities.SendEmail(emailID, "Link for Recover Password", body);
                            res = "valid";
                        }
                        else
                        {
                            string b2 = Request.Url.Authority;
                            string b6 = "http://" + b2 + "/home/RecoverPassWord?ActivationCode=" + User1.Guid.ToString();
                            string body = "Hello " + ",";
                            body += "<br /><br />Please click the following link to Reset Your PassWord";
                            body += "<br /><a href = '" + b6 + "'>Click here to Reset your account PassWord.</a>";
                            body += "<br /><br />Thanks";
                            Utilities.SendEmail(emailID, "Link for Recover Password", body);
                            res = "valid";
                        }
                    }
                }
                catch (Exception e)
                {
                    Utilities.InsertErrorLog(e);
                }
            }
            return Json(res, JsonRequestBehavior.AllowGet);
        }
  
    }
}
